package cn.jcet.mapreduce.inputformat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.NLineInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/8 23:21
 */
public class WholeDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args = new String[]{"E:\\code\\formatinput","e:/code/formatoutput"};
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        // 设置输入的inputFormat
        job.setInputFormatClass(WholeFileInputformat.class);
        // 设置输出的outFormat
        job.setOutputFormatClass(SequenceFileOutputFormat.class);

        // 关联输入切片格式，默认textInputFormat.class
        //job.setInputFormatClass(CombineTextInputFormat.class);
        // 使用NLineInputFormat处理记录数
        //job.setInputFormatClass(NLineInputFormat.class);
        // 设置每个切片split划分三条记录
        //NLineInputFormat.setNumLinesPerSplit(job,3);
        // 虚拟存储切片最大值设置
        //CombineTextInputFormat.setMaxInputSplitSize(job,20971520);



        job.setJarByClass(WholeDriver.class);

        job.setMapperClass(WholeMapper.class);
        job.setReducerClass(WholeReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(BytesWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(BytesWritable.class);

        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);


    }
}
